From c7ef6970295c812774a09c31909007dd581a27a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?utf8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Mon, 9 Apr 2018 19:07:10 +0000 Subject: [PATCH] GDK W32: set update frequency and timestamp There is no easily apparent way of being notified when frame updates happene exactly, so we just query frame info at the end of each paint. If we query too often (faster than DWM refresh rate), we just get the same values twice in a row, but that is, hopefully, highly unlikely. --- gdk/win32/gdksurface-win32.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c index 9fc030395e..ed128137d1 100644 --- a/gdk/win32/gdksurface-win32.c +++ b/gdk/win32/gdksurface-win32.c @@ -36,6 +36,7 @@ #include "gdkenumtypes.h" #include "gdkwin32.h" #include "gdkdisplayprivate.h" +#include "gdkframeclockprivate.h" #include "gdkmonitorprivate.h" #include "gdkwin32surface.h" #include "gdkwin32cursor.h" @@ -337,12 +338,43 @@ gdk_win32_surface_begin_paint (GdkSurface *window) { GdkSurfaceImplWin32 *impl; RECT window_rect; + DWM_TIMING_INFO timing_info; + LARGE_INTEGER tick_frequency; + GdkFrameTimings *timings = NULL; + GdkFrameClock *clock = NULL; if (window == NULL || GDK_SURFACE_DESTROYED (window)) return TRUE; impl = GDK_SURFACE_IMPL_WIN32 (window->impl); + clock = gdk_surface_get_frame_clock (window); + + if (clock) + timings = gdk_frame_clock_get_timings (clock, gdk_frame_clock_get_frame_counter (clock)); + + if (timings) + { + timings->refresh_interval = 16667; /* default to 1/60th of a second */ + timings->presentation_time = 0; + + if (QueryPerformanceFrequency (&tick_frequency)) + { + HRESULT hr; + + timing_info.cbSize = sizeof (timing_info); + hr = DwmGetCompositionTimingInfo (NULL, &timing_info); + + if (SUCCEEDED (hr)) + { + timings->refresh_interval = timing_info.qpcRefreshPeriod * (gdouble)G_USEC_PER_SEC / tick_frequency.QuadPart; + timings->presentation_time = timing_info.qpcCompose * (gdouble)G_USEC_PER_SEC / tick_frequency.QuadPart; + } + } + + timings->complete = TRUE; + } + /* Layered windows are moved *after* repaint. * We supply our own surface, return FALSE to make GDK use it. */ -- 2.30.2